package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.Announcement;
import com.hualan.sfzy.service.course.AnnouncementService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/announcement")
public class AnnouncementController {

    @Autowired
    private AnnouncementService announcementService;

    @PostMapping
    public Result add(@RequestBody Announcement entity) {
        System.out.println(entity);
        int result = announcementService.add(entity);
        if(result>0)
            return Result.success(result);
        return Result.error();
    }
    @GetMapping
    public Result find() {
        return Result.success(announcementService.find());
    }
    @GetMapping("/Vo")
    public Result findVo() {
        return Result.success(announcementService.findVo());
    }
    @GetMapping({"/{id}"})
    public Result findById(@PathVariable Integer id) {
        return Result.success(announcementService.findById(id));
    }
    @PostMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestBody Announcement entity) {
        System.out.println(entity);

        return Result.success(announcementService.findPage(pageNum, pageSize, entity));
    }
    @PutMapping
    public Result edit(@RequestBody Announcement entity) {
        System.out.println(entity);
        int result = announcementService.edit(entity);
        if(result>0)
            return Result.success(result);
        return Result.error();
    }
    @DeleteMapping({"/{id}"})
    public Result remove(@PathVariable Integer id) {
        return Result.success(announcementService.remove(id));
    }
    @DeleteMapping("/batch")
    public Result removeBatch(Integer[] ids) {
        return Result.success(announcementService.removeBatch(ids));
    }



}
